package cn.hicard.risk.interf.tools;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

public class Post extends Thread  {
    private String sContent;
    private String sUrl;
    public Post(String url,String content) {
        super();
        sUrl = url;
        sContent = content;
       
    }
    public void run() {
        // TODO Auto-generated method stub
        postjson(sUrl,sContent);
    }
    public  String postjson(String actionUrl,String strcontent){
        System.out.println(actionUrl);
        System.out.println(strcontent);
        String result="";
        try {
            HttpPost httppost=new HttpPost(actionUrl);
            httppost.setEntity(new StringEntity(strcontent, "UTF-8"));
            
            HttpParams httpParameters=new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
            HttpConnectionParams.setSoTimeout(httpParameters, 20000);  
            HttpClient http = new DefaultHttpClient(httpParameters);
            
            HttpResponse response=http.execute(httppost);
            if(response.getStatusLine().getStatusCode()==200){//如果状态码为200,就是正常返回
               result=EntityUtils.toString(response.getEntity(),"UTF-8"); 
            }
            
     
        }catch (ClientProtocolException cpe) {
            
            cpe.toString();
        }catch (Exception ex) {
            ex.toString();
        }
            return result;
    }
    public String getSContent() {
        return sContent;
    }
    public void setSContent(String content) {
        sContent = content;
    }
    public String getSUrl() {
        return sUrl;
    }
    public void setSUrl(String url) {
        sUrl = url;
    }
   
}
